package com.example.campsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.campsystem.entity.Favorites;
import com.example.campsystem.service.FavoritesService;
import com.example.campsystem.mapper.FavoritesMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
* @author GJC
* @description 针对表【favorites(收藏表)】的数据库操作Service实现
* @createDate 2025-04-20 23:23:47
*/
@Service
public class FavoritesServiceImpl extends ServiceImpl<FavoritesMapper, Favorites>
    implements FavoritesService{
    @Override
    public List<Favorites> getFavoritesList(Long userId) {
        QueryWrapper<Favorites> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", userId);
        return this.baseMapper.selectList(queryWrapper);
    }
    @Override
    public boolean delete(Favorites favorites) {
        QueryWrapper<Favorites> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", favorites.getUserId());
        queryWrapper.eq("target_id", favorites.getTargetId());
        queryWrapper.eq("type", favorites.getType());
        return this.baseMapper.delete(queryWrapper) > 0;
    }
    @Override
    public boolean add(Favorites favorites) {
        QueryWrapper<Favorites> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", favorites.getUserId());
        queryWrapper.eq("target_id", favorites.getTargetId());
        queryWrapper.eq("type", favorites.getType());
        return this.baseMapper.insert(favorites) > 0;
    }
    @Override
    public boolean check(Favorites favorites){
        QueryWrapper<Favorites> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("user_id", favorites.getUserId());
        queryWrapper.eq("target_id", favorites.getTargetId());
        queryWrapper.eq("type", favorites.getType());
        return this.baseMapper.selectList(queryWrapper).size() > 0;
    }
}




